var app = getApp();
const skinBehavior = require('../../../../utils/themeSkin/skinBehavior');
Page({
  behaviors: [skinBehavior],
  /**
   * 页面的初始数据
   */
  data: {
    store_id: "",
    current_index: 0,
    brand_pic_tag_list: [],
    photo_list: [],
    show_photo: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.store_id = options.store_id;
    this.getData();
  },
  show_all() {
    this.setData({
      current_index: 0,
      show_photo: this.data.photo_list
    })
  },
  previewImg(e){
    let ind;
    ind = e.currentTarget.dataset.key;
    wx.previewImage({
      current: ind?this.data.show_photo[ind]:this.data.show_photo, // 当前显示图片的http链接
      urls: this.data.show_photo // 需要预览的图片http链接列表
    });
  },
  change(e) {
    let current_index = e.currentTarget.dataset.index + 1;
    let item = e.currentTarget.dataset.item
    let show_photo = [];
    item.pics.forEach(item=>{
        show_photo.push(item.image_url)
    })
    this.setData({
      current_index,
      show_photo,
    })
  },
  getData() {
    app._postNetWork({
      url: app.getNetAddresss('plugin.local-life.api.store.info'),
      data: {
        id: this.data.store_id * 1
      },
      success: resdata => {
        let {
          result,
          msg,
          data
        } = resdata.data;
        if (result) {
          let photo_list = []
          data.has_one_brand.brand_pic_tag_list.forEach(item => {
            if (item.pics.lenth !== 0) {
              item.pics.forEach(c_item => {
                photo_list.push(c_item.image_url);
              })
            }
          })
          let brand_pic_list = [];
          if (data.has_one_brand.brand_pic_list.length !== 0) {
              data.has_one_brand.brand_pic_list.forEach(item => {
                  brand_pic_list.push(item.image_url);
              })
          }
 

          photo_list =  photo_list.concat(brand_pic_list);
          this.setData({
            photo_list,
            show_photo: photo_list,
            brand_pic_tag_list: data.has_one_brand.brand_pic_tag_list
          })

        } else {
          app.tips(msg);
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})